<?php
class My_Session{
    private static $isInit=0;
    private $obj = null;
	public function __construct($key){
        $sessionHandle = getInit("session.handle");
        $obj = null;
        if($sessionHandle == "memcache"){
            $obj = new My_Session_Memcache($key);
        }elseif($sessionHandle == "db"){
            $obj = new My_Session_Db($key);
        }
        if($obj){
            if(!self::$isInit){
                $obj->start();
            }
            $this->obj = $obj;
        }
	}

	public function __get($name)
    {
        if($this->obj){
            return $this->obj->get($name);
        }else{
            return isset($_SESSION[$name])?  $_SESSION[$name]:null;
        }
    }

    public function __set($name, $value)
    {
        if($this->obj){
            return $this->obj->set($name, $value);
        }else{
            $_SESSION[$name] = $value;
        }
    }
}
